package edu.upol.paradise.compiler.types;

import java.util.HashMap;

import org.apache.log4j.Logger;

import edu.upol.paradise.runtime.FunctionArgumentsHeader;
import edu.upol.paradise.runtime.ParadiseRuntime;

public class ParadiseFunction extends ParadiseFunctor {
	static final Logger log = Logger.getLogger(ParadiseFunction.class);
	
	private String source;
	private int lineNo;
	private String uuid;
	private String name;
	private FunctionArgumentsHeader header;
	
	private HashMap<String, ParadiseObject> boundVariableValues
		= new HashMap<String, ParadiseObject>();

	public boolean valueEquals(ParadiseObject other) {
		if (other == this)
			return true;
		return false;
	}
	
	@Override
	public String toString(){
		return name;
	}

	public int atomHashId() {
		return uuid.hashCode();
	}

	@SuppressWarnings("unchecked")
	@Override
	public ParadiseObject run(ParadiseRuntime runtime,
			VariablePassingWrapper arguments) throws Exception {
		return runtime.executeBlock(runtime.findCompiledFunction(uuid), source, name, lineNo, arguments, 
				(HashMap<String, ParadiseObject>)boundVariableValues.clone());
	}

	@Override
	public FunctionArgumentsHeader getHeader() {
		return header;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public int getLineNo() {
		return lineNo;
	}

	public void setLineNo(int lineNo) {
		this.lineNo = lineNo;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public HashMap<String, ParadiseObject> getBoundVariableValues() {
		return boundVariableValues;
	}

	public void setBoundVariableValues(HashMap<String, ParadiseObject> boundVariableValues) {
		this.boundVariableValues = boundVariableValues;
	}

	public void setHeader(FunctionArgumentsHeader header) {
		this.header = header;
	}
}
